首页

欢迎

 

Welcome

欢迎来到这里, 这是一个学习数学、讨论数学的网站.

转到问题

请输入问题号, 例如: 2512

IMAGINE, THINK, and DO
How to be a scientist, mathematician and an engineer, all in one?
--- S. Muthu Muthukrishnan

Local Notes

Local Notes 是一款 Windows 下的笔记系统.

Local Notes 下载

Sowya

Sowya 是一款运行于 Windows 下的计算软件.

详情

下载 Sowya.7z (包含最新版的 Sowya.exe and SowyaApp.exe)


注: 自 v0.550 开始, Calculator 更名为 Sowya. [Sowya] 是吴语中数学的发音, 可在 cn.bing.com/translator 中输入 Sowya, 听其英语发音或法语发音.





注册

欢迎注册, 您的参与将会促进数学交流. 注册

在注册之前, 或许您想先试用一下. 测试帐号: usertest 密码: usertest. 请不要更改密码.


我制作的 slides

Problem

随机显示问题

Problèmes d'affichage aléatoires

软件 >> C++
Questions in category: C++ (C++).

C 语言中打开文件的代码

Posted by haifeng on 2023-03-05 11:27:43 last update 2023-03-05 11:42:17 | Answers (0)


 

FILE* inputFile;

const char * file_in;

if ((inputFile = fopen(file_in, "r")) == NULL)     //读取输入文件
{
printf("\nerror: 无法打开输入文件: %s\n\n", file_in);
std::cerr << "Parser: could not open input file '" << file_in << "'!\n";
return EXIT_FAILURE;
}

 

但若在 Visual Studio 下, 会提示 fopen 不安全, 建议使用 fopen_s.

//Declaring a variable of type errno_t to store the return value of fopen_s
    errno_t error_code1; 
    //Opening file in r mode
    error_code1 = fopen_s(&inputFile, file_in, "r");
    if (error_code1 != 0) {
        printf("Error! Failed to open file %s in r mode!", file_in);
    }